<?php
/**
 * @Author: king
 * @Last Modified by:   king
 * Date: 2018/6/14
 * Time: 10:26
 */
namespace App\Tools;

use App\Models\Api\Rectification as RectificationModel;
use App\Models\Api\User;
use App\Models\Api\Orders;
use App\Models\TOrders;
use App\Models\Api\MessageCenter;

use App\Tools\Push;
use App\Tools\Rectification;
use DB,Cache;
use Illuminate\Contracts\Queue\Job;
/**
 * 订单
 * Class RectificationJob
 * @package app\common\lib
 */
class TorderJob
{
    /**
     * @param job $job
     * @param $data
     * @throws exception\DbException
     * @throws exception\ApiException
     */
    public function task1(Job $job, $data)
    {
        if ($job->attempts() > 20)
        {
            $job->delete();// 任务重复执行1次以上  删除该任务
        }
        $TOrdersInfo = TOrders::where("id",$data['id'])->find();
         if (empty($TOrdersInfo)){
            return;
        }
        if(time()-$TOrdersInfo['create_time'] > 5*60){
            TOrders::where("id",$data['id'])->save([
                'status'=>2,
                'update_time'=>time()
            ]);
            //如果任务执行成功后 记得删除任务，不然这个任务会重复执行，直到达到最大重试次数后失败后，执行failed方法
            $job->delete();
        }

    }

    public function failed($data)
    {
        // ...任务达到最大重试次数后，失败了


        // 重新发布任务
        //Queue::push('app\common\lib\Job@task1', $data, 'rectification');
    }
}
